Installation & Setup
Install GitHub CLI
bash
1# macOS2brew install gh3
4# Windows (winget)5winget install --id GitHub.cli6
7# Windows (Chocolatey)8choco install gh9
10# Ubuntu / Debian11sudo mkdir -p -m 755 /etc/apt/keyrings \12 && wget -qO- https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null \13 && sudo chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg \14 && echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \15 && sudo apt update \16 && sudo apt install gh -y17
18# Fedora19sudo dnf install gh20
21# Arch Linux22sudo pacman -S github-cli23
24# Verify installation25gh --versionShell Autocomplete
bash
1# Bash2gh completion -s bash | sudo tee /etc/bash_completion.d/gh_completion > /dev/null3
4# Zsh5gh completion -s zsh > ~/.zfunc/_gh6
7# Fish8gh completion -s fish > ~/.config/fish/completions/gh.fishUpdate GitHub CLI
bash
1gh extension upgrade gh-copilot # update a single extension2gh extension upgrade --all # update all extensions3brew upgrade gh # macOS with HomebrewAuthentication
Login & Logout
bash
1gh auth login # interactive login (HTTPS or SSH)2gh auth login --web # login via browser3gh auth login --with-token < token.txt # login with personal access token4gh auth login --hostname github.example.com # GitHub Enterprise Server5gh auth status # show current authentication status6gh auth logout # log out of GitHub7gh auth refresh # refresh stored credentials8gh auth refresh --scopes write:packages,delete:packages # add extra scopesToken Scopes Reference
| Scope | Purpose |
|---|---|
repo | Full control of private repositories |
repo:invite | Access repository invitations |
public_repo | Access public repositories |
read:org | Read organization membership |
write:org | Manage organization membership |
read:user | Read user profile data |
gist | Create and manage gists |
workflow | Manage GitHub Actions workflows |
delete_repo | Delete repositories |
write:packages | Upload packages to GitHub Packages |
admin:public_key | Manage public SSH keys |
Configuration
View & Set Configuration
bash
1gh config list # show all config values2gh config get editor # get a specific config value3gh config set editor "code --wait" # set default editor4gh config set git_protocol ssh # use SSH for git operations5gh config set git_protocol https # use HTTPS for git operations6gh config set prompt disabled # disable interactive promptsCommon Configuration Options
| Option | Values | Description |
|---|---|---|
git_protocol | https, ssh | Protocol used for git operations |
editor | editor command | Default editor for interactive commands |
prompt | enabled, disabled | Enable/disable interactive prompts |
pager | pager command | Program used to paginate output |
Repositories
Create & Clone
bash
1gh repo create my-repo # create a new public repo2gh repo create my-repo --private # create a private repo3gh repo create my-repo --internal # create an internal repo (Enterprise)4gh repo create my-org/my-repo --private --clone # create in org and clone5gh repo create --source=. --public --push # push current directory6
7gh repo clone owner/repo # clone a repository8gh repo clone owner/repo my-dir # clone into custom directory9gh repo fork owner/repo # fork a repository10gh repo fork owner/repo --clone # fork and clone locally11gh repo fork owner/repo --org my-org # fork into an organizationView & Manage
bash
1gh repo view # view current repository info2gh repo view owner/repo # view specific repository3gh repo view --web # open repository in browser4gh repo view --branch main # view specific branch5
6gh repo list # list your repositories7gh repo list owner --limit 50 # list repositories for a user/org8gh repo list --source # list only source repos (no forks)9gh repo list --fork # list only forks10
11gh repo delete owner/repo # delete a repository12gh repo archive owner/repo # archive a repository13gh repo unarchive owner/repo # unarchive a repository14gh repo rename my-new-name # rename current repository15gh repo edit --description "New description" # update repo descriptionSync & Remotes
bash
1gh repo set-default owner/repo # set default repository for current dir2gh repo sync # sync current branch with upstream3gh repo sync owner/repo --branch main # sync specific branch4gh repo sync --force # force sync (overwrite local changes)Pull Requests
Create Pull Requests
bash
1gh pr create # create PR interactively2gh pr create --title "Fix login" --body "Closes #123"3gh pr create --fill # auto-fill title/body from commits4gh pr create --fill-first # use first commit for title/body5gh pr create --draft # create as draft PR6gh pr create --web # open PR creation in browser7gh pr create --base main --head feature-branch8gh pr create --reviewer username1,username29gh pr create --assignee @me10gh pr create --label bug,critical11gh pr create --project "Q3 Roadmap"List & View
bash
1gh pr list # list open PRs2gh pr list --state all # list all PRs3gh pr list --state merged # list merged PRs4gh pr list --state closed # list closed PRs5gh pr list --author @me # authored by you6gh pr list --assignee @me # assigned to you7gh pr list --review-requested @me # requesting your review8gh pr list --label bug # filter by label9gh pr list --limit 50 # limit results10gh pr list --json number,title,author,state # JSON output11
12gh pr view 42 # view PR details13gh pr view 42 --web # open PR in browser14gh pr view --comments # view PR with commentsCheckout & Review
bash
1gh pr checkout 42 # checkout PR locally2gh pr checkout 42 --branch pr-42 # checkout into named branch3gh pr checkout 42 --recurse-submodules # also update submodules4gh pr checkout 42 --force # reset branch and checkout PR5
6gh pr diff 42 # view PR diff7gh pr diff 42 --color always # force color output8gh pr diff 42 --patch # output in patch format9
10gh pr review 42 --approve # approve PR11gh pr review 42 --request-changes -b "Needs tests"12gh pr review 42 --comment -b "Looks good, one question"13gh pr review 42 --body "Approved" # non-interactive approval14gh pr checks 42 # view PR check statusMerge & Close
bash
1gh pr merge 42 # merge PR interactively2gh pr merge 42 --merge # create a merge commit3gh pr merge 42 --squash # squash and merge4gh pr merge 42 --rebase # rebase and merge5gh pr merge 42 --auto # enable auto-merge6gh pr merge 42 --delete-branch # delete branch after merging7gh pr merge 42 --admin # use admin privileges to merge8
9gh pr close 42 # close PR without merging10gh pr close 42 --delete-branch # close and delete branch11gh pr reopen 42 # reopen closed PR12gh pr ready 42 # mark draft PR as readyUpdate PRs
bash
1gh pr edit 42 --title "New title"2gh pr edit 42 --body "Updated description"3gh pr edit 42 --add-label enhancement4gh pr edit 42 --remove-label bug5gh pr edit 42 --add-assignee username6gh pr edit 42 --add-reviewer username7gh pr comment 42 --body "Great work!"Issues
Create Issues
bash
1gh issue create # create issue interactively2gh issue create --title "Bug report" --body "Description here"3gh issue create --label bug,urgent4gh issue create --assignee @me5gh issue create --milestone v1.06gh issue create --project "Backlog"List & View
bash
1gh issue list # list open issues2gh issue list --state all # list all issues3gh issue list --state closed # list closed issues4gh issue list --label bug # filter by label5gh issue list --assignee @me # assigned to you6gh issue list --author @me # created by you7gh issue list --limit 100 # limit results8gh issue list --search "error in production"9
10gh issue view 42 # view issue details11gh issue view 42 --web # open issue in browser12gh issue view 42 --comments # view with commentsManage Issues
bash
1gh issue edit 42 --title "Updated title"2gh issue edit 42 --add-label fixed3gh issue edit 42 --remove-label bug4gh issue edit 42 --add-assignee username5gh issue edit 42 --milestone v1.16gh issue close 42 # close issue7gh issue close 42 --reason completed # close with reason8gh issue reopen 42 # reopen issue9gh issue comment 42 --body "Still investigating"10gh issue delete 42 # delete issueLock & Pin
bash
1gh issue lock 42 # lock issue conversation2gh issue lock 42 --reason spam # lock with reason3gh issue unlock 42 # unlock issue conversation4gh issue pin 42 # pin issue5gh issue unpin 42 # unpin issueReleases
Create Releases
bash
1gh release create v1.0.0 # create release from tag2gh release create v1.0.0 --title "Version 1.0.0"3gh release create v1.0.0 --notes "Release notes"4gh release create v1.0.0 --generate-notes # auto-generate from PRs5gh release create v1.0.0 --draft # create draft release6gh release create v1.0.0 --prerelease7gh release create v1.0.0 ./app.zip ./checksums.txt # upload assets8gh release create v1.0.0 --target main # use specific commit/branchManage Releases
bash
1gh release list # list releases2gh release view v1.0.0 # view release details3gh release view v1.0.0 --web # open release in browser4gh release download v1.0.0 # download all assets5gh release download v1.0.0 --pattern "*.zip"6gh release download v1.0.0 --archive tar.gz7gh release edit v1.0.0 --draft=false # publish draft8gh release delete v1.0.0 # delete release9gh release upload v1.0.0 asset.zip # upload asset to existing release10gh release delete-asset v1.0.0 asset.zip # delete an assetGitHub Actions Workflows
List & View
bash
1gh workflow list # list workflows2gh workflow list --all # include disabled workflows3gh workflow view deploy.yml # view workflow details4gh workflow view deploy.yml --web # open workflow in browser5gh workflow view deploy.yml --yaml # view workflow YAMLRun & Manage
bash
1gh workflow run deploy.yml # trigger workflow manually2gh workflow run deploy.yml --ref main3gh workflow run deploy.yml -f env=production -f version=1.2.34gh workflow run deploy.yml --raw-field config="$(cat config.json)"5
6gh workflow enable deploy.yml # enable workflow7gh workflow disable deploy.yml # disable workflow8gh workflow delete deploy.yml # delete workflowWorkflow Runs
bash
1gh run list # list recent workflow runs2gh run list --workflow deploy.yml # list runs for specific workflow3gh run list --branch main # filter by branch4gh run list --status failed # filter by status5gh run list --limit 206
7gh run view 1234567890 # view run summary8gh run view 1234567890 --log # view full logs9gh run view 1234567890 --log-failed # view only failed job logs10gh run view 1234567890 --web # open run in browser11gh run view --job 9876543210 # view specific job12
13gh run watch 1234567890 # watch run in real-time14gh run rerun 1234567890 # rerun failed jobs15gh run rerun --failed # rerun all failed jobs16gh run cancel 1234567890 # cancel a run17gh run delete 1234567890 # delete a run18gh run download 1234567890 # download artifacts19gh run download 1234567890 --name dist # download specific artifactCodespaces
Create & Manage
bash
1gh codespace create # create a codespace2gh codespace create --repo owner/repo3gh codespace create --branch main4gh codespace create --machine basicLinux32gb5gh codespace list # list your codespaces6gh codespace list --owner owner7
8gh codespace code my-codespace # open in VS Code9gh codespace code --web my-codespace # open in browser10gh codespace ssh my-codespace # SSH into codespace11gh codespace logs my-codespace # view codespace logs12
13gh codespace stop my-codespace # stop codespace14gh codespace delete my-codespace # delete codespace15gh codespace delete --all # delete all codespacesGists
bash
1gh gist create file.txt # create private gist from file2gh gist create file.txt --public # create public gist3gh gist create -d "My snippet" file.txt # with description4gh gist create --filename sample.js < code.js5gh gist list # list your gists6gh gist view <gist-id> # view a gist7gh gist view <gist-id> --files # list gist files8gh gist edit <gist-id> # edit a gist9gh gist delete <gist-id> # delete a gist10gh gist clone <gist-id> # clone a gist locallySearch
bash
1gh search repos "topic:kubernetes" # search repositories2gh search repos "language:go stars:>1000"3gh search code "function main" --repo owner/repo4gh search code "TODO" --extension js5gh search issues "bug" --repo owner/repo6gh search issues --assignee @me --state open7gh search prs "feature" --repo owner/repo8gh search prs --review-requested=@me --state=open9gh search commits "fix authentication"Organizations & Teams
bash
1gh org list # list your organizations2gh org view my-org # view organization details3gh org view my-org --web # open org in browser4
5gh team list --org my-org # list teams in organization6gh team view my-org/my-team # view team details7gh team create my-org/my-team --name "Platform Team"Projects
bash
1gh project list # list your projects2gh project list --owner my-org # list organization projects3gh project view 1 # view project details4gh project view 1 --web # open project in browser5gh project create --title "Roadmap" --owner my-org6gh project edit 1 --title "New Title"7gh project delete 1 # delete projectSecrets & Variables
Repository Secrets
bash
1gh secret set MY_SECRET # set secret (prompts for value)2gh secret set MY_SECRET < secret.txt # set from file3gh secret set MY_SECRET --env production # set environment secret4gh secret set MY_SECRET --org my-org --visibility all5gh secret list # list repo secrets6gh secret delete MY_SECRET # delete repo secretVariables
bash
1gh variable set MY_VAR --body "value"2gh variable set MY_VAR --env production --body "prod-value"3gh variable list # list variables4gh variable get MY_VAR # get variable value5gh variable delete MY_VAR # delete variableCodespaces & Dependabot Secrets
bash
1gh secret set MY_SECRET --user # user-level secret for Codespaces2gh secret set MY_SECRET --codespaces3gh secret set MY_SECRET --dependabotSSH & GPG Keys
bash
1gh ssh-key list # list SSH keys2gh ssh-key add ~/.ssh/id_ed25519.pub # add SSH key3gh ssh-key add ~/.ssh/id_ed25519.pub --title "MacBook Pro"4gh ssh-key delete <key-id> # delete SSH key5
6gh gpg-key list # list GPG keys7gh gpg-key add key.asc # add GPG key8gh gpg-key delete <key-id> # delete GPG keyExtensions
Manage Extensions
bash
1gh extension list # list installed extensions2gh extension install owner/gh-extension # install extension3gh extension install https://github.com/owner/gh-extension4gh extension remove owner/gh-extension5gh extension upgrade owner/gh-extension6gh extension upgrade --all # upgrade all extensions7gh extension search copilot # search for extensions8gh extension create my-extension # scaffold a new extensionPopular Extensions
| Extension | Purpose |
|---|---|
github/gh-copilot | GitHub Copilot in the CLI |
seachicken/gh-poi | Delete local branches safely |
meiji163/gh-notify | GitHub notifications in terminal |
rednaw/exclamation | Bulk add issues/PRs to projects |
Direct API Access
bash
1gh api user # GET current user2gh api repos/owner/repo/issues # list issues3gh api repos/owner/repo/issues -f title="Bug" -f body="Details" # create issue4gh api repos/owner/repo/issues/1 -X PATCH -f state=closed # close issue5gh api repos/owner/repo --method DELETE6gh api graphql -f query='{ viewer { login } }'7gh api repos/owner/repo/releases --jq '.[0].tag_name' # with jq filter8gh api --paginate repos/owner/repo/issues # paginate automatically9gh api --preview mercy-preview ... # enable preview APIUseful Aliases
bash
1# Add to your shell config2alias ghpr='gh pr create --fill'3alias ghpc='gh pr checkout'4alias ghpm='gh pr merge --squash --delete-branch'5alias ghil='gh issue list --assignee @me'6alias ghrl='gh release list --limit 10'7alias ghwl='gh workflow list'8alias ghrw='gh run watch'Output Formatting
bash
1gh pr list --json number,title,author,state # JSON output2gh pr list --json number,title --jq '.[] | "\(.number): \(.title)"'3gh issue list --template '{{range .}}{{.number}} {{.title}}{{\n}}{{end}}'4gh repo list --limit 5 --web # open results in browser5gh ... --silent # suppress outputCommon JSON Fields
bash
1gh pr view 42 --json number,title,body,state,author,headRepository,baseRefName2gh issue view 42 --json number,title,body,state,labels,assignees3gh release view v1.0.0 --json tagName,name,body,publishedAt,assetsEnvironment Variables
| Variable | Description |
|---|---|
GH_TOKEN | Authentication token (alternative to gh auth login) |
GITHUB_TOKEN | Fallback authentication token |
GH_HOST | Default GitHub host (for Enterprise Server) |
GH_REPO | Default repository (owner/repo) |
GH_EDITOR | Default editor override |
GH_PAGER | Default pager override |
GH_DEBUG | Set to 1 or api to enable debug logging |
GH_NO_UPDATE_NOTIFIER | Set to 1 to disable update checks |
Tips & Best Practices
bash
1# Use --web to open any view in browser when you need the UI2gh pr view 42 --web3
4# Combine gh with git for powerful workflows5git checkout -b feature && gh pr create --fill6
7# Auto-fill PRs from conventional commits8gh pr create --fill9
10# Review PRs from terminal with diffs and comments11gh pr checkout 42 && gh pr diff && gh pr review12
13# Use jq with --json for scripting14gh pr list --json number,title --jq '.[] | "#\(.number) \(.title)"'15
16# Set default repo to avoid typing owner/repo repeatedly17cd my-repo && gh repo set-default owner/repo